<style>
  .picImg {
    width: 40px;
    height: 40px;
  }
</style>
<template>
  <div class="app-container">
    <!--&lt;!&ndash; 查询和其他操作 &ndash;&gt;-->
    <div class="filter-container">
      <el-button class="filter-item" type="primary" icon="el-icon-edit"
                 @click="handleAdd">新增
      </el-button>
    </div>

    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row
              :header-cell-style="{background:'#92D3FF',color:'#fff'}">

      <!--<el-table-column fixed align="center" min-width="80" label="关联ID" prop="ID"/>-->
      <el-table-column fixed align="center" min-width="100" label="关联类型" prop="type">
        <template slot-scope="scope">
          <span>{{ scope.row.type ? '权益服务商' : '保代公司'}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" min-width="110" label="保险公司名称" prop="suranceName"/>
      <el-table-column align="center" min-width="110" label="保代公司名称" prop="agentName"/>
      <el-table-column align="center" min-width="110" label="保理公司名称" prop="factoringName"/>
      <el-table-column align="center" min-width="120" label="垫资额度 (万元)" prop="amount"/>
      <el-table-column align="center" min-width="140" label="垫资总日息 (‱)" prop="interestAll"/>
      <el-table-column align="center" min-width="140" label="保理公司日息 (‱)" prop="interestFactoring"/>
      <el-table-column align="center" min-width="200" label="服务费账户号" prop="serviceAccount"/>
      <el-table-column align="center" min-width="200" label="共管账户号" prop="account"/>
      <el-table-column align="center" min-width="200" label="共管账户名称" prop="accName"/>
      <el-table-column align="center" min-width="200" label="共管账户开户银行名称" prop="interBankName"/>
      <!--<el-table-column align="center" min-width="200" label="共管账户联行号" prop="interBankNo"/>-->
      <el-table-column align="center" min-width="200" label="共管账户渠道编号" prop="channelNo"/>
      <el-table-column align="center" min-width="110" label="是否代付中转" prop="isRepay">
        <template slot-scope="scope">
          <span>{{ scope.row.isRepay ? '代付' : '不代付'}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" min-width="200" label="代付账号" prop="repayAccount"/>
      <el-table-column align="center" min-width="170" label="创建时间" prop="timeAdd"/>
      <el-table-column fixed="right" align="center" label="操作" width="300" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="success" size="mini"
                     @click="handleBalance(scope.row)">余额
          </el-button>
          <el-button type="primary" size="mini"
                     @click="handleEdit(scope.row)">编辑
          </el-button>
          <el-popover
            placement="top"
            width="200"
            trigger="manual"
            :ref="'popover-' + scope.row.bankCode">
            <p>确定删除该数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[`popover-` + scope.row.bankCode].doClose()">取消</el-button>
              <el-button type="primary" size="mini" @click="doDelete(scope.row)">确定</el-button>
            </div>
            <el-button style="margin-left: 10px;" type="danger" size="mini" slot="reference" @click="$refs[`popover-` + scope.row.bankCode].doShow()">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <!--<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                @pagination="getList"/>-->
    <!-- 余额对话框 -->
    <el-dialog :visible.sync="acclistDialogVisible" title="账户余额"  width="900px" :close-on-click-modal="false">
      <el-table v-loading="acclistLoading" :data="acclist" element-loading-text="正在查询中。。。" border fit highlight-current-row
                :header-cell-style="{background:'#92D3FF',color:'#fff'}">
        <el-table-column fixed align="center" max-width="300" label="账户号" prop="account"/>
        <el-table-column align="center" min-width="100" label="当前余额 (元)" prop="balance"/>
        <el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="success" size="mini"
                       @click="handleBankserial(scope.row)">明细
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--明细对话框-->
      <el-dialog :visible.sync="acclistDialogChildVisible" title="余额明细" width="1000px" append-to-body :close-on-click-modal="false">
        <!--查询表单-->
        <el-form ref="editChildForm" :rules="editChildFormRules" :model="editChildForm" status-icon label-position="right"
                 label-width="100px" style="width: 900px;">
          <el-form-item label="收付方向" prop="payRecv">
            <el-radio-group v-model="editChildForm.payRecv">
              <el-radio :label="2">全部</el-radio>
              <el-radio :label="0">收款</el-radio>
              <el-radio :label="1">付款</el-radio>
            </el-radio-group>
          </el-form-item>
          <div style="display: flex">
            <el-form-item label="开始日期" prop="startTime">
              <el-date-picker
                v-model="editChildForm.startTime"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="结束日期" prop="endTime">
              <el-date-picker
                v-model="editChildForm.endTime"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
            <div style="margin-left: 30px">
              <el-button type="primary" @click="doQuery" icon="el-icon-search">查询</el-button>
            </div>
          </div>
        </el-form>
        <!-- 明细查询结果 -->
        <el-table v-loading="bankserialListLoading" :data="bankserialList" element-loading-text="正在查询中。。。"
                  border fit highlight-current-row :header-cell-style="{background:'#92D3FF',color:'#fff'}">
          <span style="text-align: left;display: inline-block;width: 100%;margin-left: -55%;" slot="empty">暂无数据</span>
          <el-table-column fixed align="center" min-width="100" label="流水号" prop="serialNo"/>
          <!--<el-table-column align="center" min-width="100" label="凭证号" prop="voucherNo"/>-->
          <el-table-column align="center" min-width="150" label="交易订单号" prop="orderNo"/>
          <el-table-column align="center" min-width="120" label="交易时间" prop="tradeTime"/>
          <el-table-column align="center" min-width="100" label="收付方向" prop="payRecv"/>
          <el-table-column align="center" min-width="100" label="币种" prop="currency"/>
          <el-table-column align="center" min-width="200" label="金额 (元)" prop="money"/>
          <el-table-column align="center" min-width="100" label="收款账号" prop="recvAccount"/>
          <el-table-column align="center" min-width="110" label="收款户名" prop="recvAccountName"/>
          <el-table-column align="center" min-width="110" label="收款联行号" prop="recvBankNo"/>
          <el-table-column align="center" min-width="200" label="收款银行名称" prop="recvBankName"/>
          <el-table-column align="center" min-width="100" label="付款账号" prop="payAccount"/>
          <el-table-column align="center" min-width="200" label="付款户名" prop="payAccountName"/>
          <el-table-column align="center" min-width="200" label="付款联行号" prop="payBankNo"/>
          <!--<el-table-column align="center" min-width="200" label="付款银行名称" prop="payBankName"/>
          <el-table-column align="center" min-width="200" label="用途" prop="usage"/>
          <el-table-column align="center" min-width="170" label="摘要" prop="abstract"/>
          <el-table-column align="center" min-width="170" label="附言" prop="postscript"/>-->
          <el-table-column fixed="right" align="center" min-width="170" label="支付结果" prop="payResult"/>
          <el-table-column fixed="right" align="center" min-width="170" label="结果原因" prop="reason"/>
        </el-table>
        <pagination v-show="bankserialTotal>0" :total="bankserialTotal" :page.sync="bankserialListQuery.page"
                    :limit.sync="bankserialListQuery.limit"
                    @pagination="getBankserialList(account)"/>
      </el-dialog>
    </el-dialog>
    <!-- 新增三方关联对话框 -->
    <el-dialog :visible.sync="editDialogVisible" :title="dialogStatus == 'create' ? '新增三方关联' : '编辑三方关联'" width="900px"
               :close-on-click-modal="false">
      <el-form ref="editForm" :rules="editFormRules" :model="editForm" status-icon label-position="right"
               label-width="160px" style="padding-right: 20px;">
        <div style="display: flex">
          <div style="flex: 1; margin-right: 40px">
            <el-form-item label="关联类型" prop="type">
              <el-radio-group v-model="editForm.type" @change="typeChange">
                <el-radio :label="0">保代公司</el-radio>
                <el-radio :label="1">权益服务商</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="保险公司" prop="insuranceID">
              <el-select v-model="editForm.insuranceID"
                         placeholder="请选择">
                <el-option
                  v-for="item in insuranceList"
                  :key="item.ID"
                  :label="item.companyName"
                  :value="item.ID">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="保代公司/权益服务商" prop="agentID">
              <el-select v-model="editForm.agentID" @change="agenChange"
                         placeholder="请选择">
                <el-option
                  v-for="item in agentList"
                  :key="item.ID"
                  :label="item.companyName"
                  :value="item.ID">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="保理公司" prop="factoringID">
              <el-select  @change="bankNameChange" v-model="editForm.factoringID"
                         placeholder="请选择">
                <el-option
                  v-for="item in factoringList"
                  :key="item.ID"
                  :label="item.companyName"
                  :value="item.ID">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="垫资额度" prop="amount">
              <el-input v-model="editForm.amount" placeholder="垫资额度" style="width: 80%"/>
              <span style="margin-left: 10px">万元</span>
            </el-form-item>
            <el-form-item label="垫资总日息" prop="interestAll">
              <el-input v-model="editForm.interestAll" placeholder="垫资总日息" style="width: 80%"/>
              <span style="margin-left: 20px">‱</span>
            </el-form-item>
            <el-form-item label="保理公司日息" prop="interestFactoring">
              <el-input v-model="editForm.interestFactoring" placeholder="保理公司日息"  style="width: 80%"/>
              <span style="margin-left: 20px">‱</span>
            </el-form-item>
            <el-form-item label="保理公司收款账号" prop="factoringAcc">
              <!--<el-input v-model="editForm.factoringAcc" placeholder="保理公司收款账号"/>-->
              <el-select v-model="editForm.factoringAcc"
                         placeholder="请选择">
                <el-option
                  v-for="item in accounts"
                  :key="item.account"
                  :label="item.account"
                  :value="item.account">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div style="flex: 1">
            <el-form-item label="服务费账户" prop="serviceAccount">
              <el-select v-model="editForm.serviceAccount"
                         placeholder="请选择">
                <el-option
                  v-for="item in surserviceList"
                  :key="item.account"
                  :label="item.name"
                  :value="item.account">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="共管账户号" prop="account">
              <el-input v-model="editForm.account" placeholder="共管账户号"/>
            </el-form-item>
            <el-form-item label="共管账户名称" prop="accName">
              <el-input v-model="editForm.accName" placeholder="共管账户名称"/>
            </el-form-item>
            <el-form-item label="共管账户银行代码" prop="bankCode">
              <el-select @change="bankChange" v-model="editForm.bankCode" placeholder="请选择" filterable style="width:100%">
                <el-option
                  v-for="item in banks"
                  :key="item.bankName"
                  :label="item.bankName"
                  :value="item.bankCode">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="共管账户联行号" prop="bankName">
              <el-input readonly="readonly" v-model="editForm.bankName" auto-complete="off" placeholder="请选择" @click.native="getUnioLs()"/>
            </el-form-item>
            <!--<el-form-item label="共管账户银行信息" prop="selectedBankInfo">
              <el-cascader
                :options="bankInfo"
                v-model="editForm.selectedBankInfo"
                @active-item-change="handleItemChange">
              </el-cascader>
            </el-form-item>-->
            <el-form-item label="共管账户渠道编号" prop="channelNo">
              <el-select v-model="editForm.channelNo"
                         placeholder="请选择">
                <el-option
                  v-for="item in channelNoList"
                  :key="item.channelNo"
                  :label="item.channelName"
                  :value="item.channelNo">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否代付中转">
              <el-switch v-model="editForm.isRepay"></el-switch>
            </el-form-item>
            <el-form-item label="代付账号">
              <!--<el-input v-model="editForm.repayAccount" :disabled="!editForm.isRepay" placeholder="代付账号"/>-->
              <el-select v-model="editForm.repayAccount":disabled="!editForm.isRepay"
                         placeholder="请选择">
                <el-option
                  v-for="item in AccTypes"
                  :key="item.account"
                  :label="item.account"
                  :value="item.account">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="doEdit">{{dialogStatus == 'create' ? '新增' : '确定'}}</el-button>
      </div>
    </el-dialog>

    <!--支行弹窗-->
    <el-dialog :visible.sync="UnionDialogVisible" title="选择开户银行名称" :close-on-click-modal="false">
      <div class="filter-container">
        <el-form :inline="true" status-icon label-position="left" class="demo-form-inline"
                 label-width="100px" style="width: 100%; margin-left:50px;">
          <el-form-item label="开户银行名称" prop="account">
            <el-input auto-complete="off" v-model="editForm1.interBankName" placeholder="开户银行名称" style="width:400px" />
          </el-form-item>
          <el-form-item>
            <el-button class="filter-item" type="primary" @click="queryUnio">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table v-loading="unionnosLoading" :data="unionnos" element-loading-text="正在查询中。。。" border fit highlight-current-row
                :header-cell-style="{background:'#92D3FF',color:'#fff'}">
        <el-table-column align="left" min-width="100" label="开户银行名称" prop="bankName"/>
        <el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="primary" size="mini"
                       @click="choose(scope.row)">选择
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total1>0" :total="total1" :page.sync="editForm1.pageNum" :limit.sync="editForm1.pageSize"
                  @pagination="getUnionnos"/>
    </el-dialog>

  </div>
</template>

<script>
  import {doGet, doPost} from '@/api'
  import {cities} from '@/utils/base'
  import {parseTime} from '@/utils'
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import checkPermission from '@/utils/permission' // 权限判断函数

  export default {
    name: 'correlation',
    components: {Pagination},
    filters: { },
      al : '',
      pageNum: '',
      pageSize: '',
    data() {
      return {
        list: [],
        total: 0,
          total1: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
        },
        dialogStatus: 'create',
        editForm: {
          type: 0,
          insuranceID: undefined,
          agentID: undefined,
          factoringID: undefined,
          amount: undefined,
          interestAll: undefined,
          interestFactoring: undefined,
          serviceAccount: undefined,
          account: undefined,
          accName: undefined,
          bankCode: undefined,
          interBankNo: undefined,
          channelNo: undefined,
          isRepay: 0,
          repayAccount: undefined,
          selectedBankInfo: undefined,
          factoringAcc: undefined,
            bankName: undefined
        },
        editFormRules: {
          type: [{required: true, message: '请选择关联类型', trigger: 'blur'}],
          insuranceID: [{required: true, message: '请选择保险公司', trigger: 'blur'}],
          agentID: [{required: true, message: '请选择保代公司/权益服务商', trigger: 'blur'}],
          factoringID: [{required: true, message: '请选择保理公司', trigger: 'blur'}],
          amount: [{required: true, message: '垫资额度不允许为空', trigger: 'blur'}],
          interestAll: [{required: true, message: '垫资总日息不允许为空', trigger: 'blur'}],
          interestFactoring: [{required: true, message: '保理公司日息不允许为空', trigger: 'blur'}],
          serviceAccount: [{required: true, message: '服务费账户不允许为空', trigger: 'blur'}],
          account: [{required: true, message: '共管账户号不允许为空', trigger: 'blur'}],
          accName: [{required: true, message: '共管账户名称不允许为空', trigger: 'blur'}],
          bankCode: [{required: true, message: '共管账户银行代码不允许为空', trigger: 'blur'}],
          interBankNo: [{required: true, message: '共管账户联行号不允许为空', trigger: 'blur'}],
          selectedBankInfo: [{required: true, message: '请选择共管账户银行信息', trigger: 'blur'}],
          factoringAcc: [{required: true, message: '保理公司收款账号不允许为空', trigger: 'blur'}],
          bankName: [{required: true, message: '共管账户联行号不允许为空', trigger: 'blur'}]
        },
        editDialogVisible: false,
        cities: cities,
        acclistDialogVisible: false, // 账户列表对话框显示标志
        acclistLoading: false, // 查看账户列表loading标志
        acclist: [], // 账户列表数据
        acclistDialogChildVisible: false, // 增加服务商账户对话框显示标志
        editChildForm: {
          payRecv: undefined,
          queryDate: undefined,
            startTime: undefined,
            endTime: undefined
        },
        editChildFormRules: {
            startTime: [{required: true, message: '请选择开始日期', trigger: 'blur'}],
            endTime: [{required: true, message: '请选择结束日期', trigger: 'blur'}]
        },
        id: undefined,
        bankserialList: [], // 明细列表
        bankserialListLoading: false,
        bankserialTotal: 0,
        bankserialListQuery: {
          page: 1,
          limit: 20,
        },
          editForm1: {
              pageNum: 1,
              pageSize: 20,
              bankCode: undefined,
              interBankName: undefined
          },
        account: undefined, // 指定账户号
        insuranceList: [],
        agentList: [],
        factoringList: [],
        surserviceList: [],
        channelNoList: [],
        bankList: [],
        bankInfo: [],
        accounts: [],
        AccTypes: [],
          banks: [],
          unionnos: [],
          agens: [],
          UnionDialogVisible: false,
          unionnosLoading: true
      }
    },
    created() {
      this.getList()
      this.getAccTypes()
        this.getBanks()
    },
    methods: {
      checkPermission,
        getBanks() {
            doGet('bank.html?op=list', {}).then(response => {
                this.banks = response.rows
            }).catch(() => {
                this.banks = []
            })
        },
        getUnionnos(subankCode, flag) {
            if (typeof(subankCode) == 'string') {
                this.pageNum = 1
                this.pageSize = 20
            } else {
                this.pageNum = subankCode.page
                this.pageSize = subankCode.limit
            }
            this.editForm1 = {
                pageNum: this.pageNum,
                pageSize: this.pageSize,
                bankCode: this.al,
                bankName: this.editForm1.interBankName,
                interBankNo: this.editForm.interBankNo,
                flag: flag
            }
            this.UnionDialogVisible = true
            this.unionnosLoading = true
            doGet('unionno.html?op=list', this.editForm1).then(response => {
                this.unionnos = response.rows
                this.total1 = response.data.totalcount
                this.unionnosLoading = false
            }).catch(() => {
                this.unionnos = []
                this.total1 = 0
                this.unionnosLoading = false
            })
        },

        bankChange(bankCode) {
            this.al = bankCode.substring(0, 3)
             var flag = '1';
            this.getUnionnos(this.al, flag)
            this.editForm.interBankNo = undefined
        },
        getAccounts(id) {
            doGet('factoring.html?op=acclist', {id}).then(response => {
                this.accounts = response.rows
            }).catch(() => {
                this.accounts = []
            })
        },
        bankNameChange(id) {
            this.getAccounts(id);
            this.editForm.factoringAcc = undefined
        },
        getAccTypes() {
            doGet('account.html?op=list', {accType: 1}).then(response => {
                this.AccTypes = response.rows
            }).catch(() => {
                this.AccTypes = []
            })
        },

      // 获取三方关联列表
      getList() {
        this.listLoading = true
        doGet('correlation.html?op=list').then(response => {
          this.list = response.rows
          this.total = response.rows.length
          this.listLoading = false
        }).catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
      },

      // 获取余额列表
      getAccList(account) {
        this.acclistLoading = true
        doGet('balance.html?op=search', {account}).then(response => {
          this.acclist = response.rows
          this.acclistLoading = false
        }).catch(response => {
          this.acclist = []
          this.acclistLoading = false
          this.$notify.error({
            title: '失败',
            message: response.message
          })
        })
      },

      // 弹出新增三方关联对话框
      handleAdd() {
        this.isSelectOptions()
        Object.keys(this.editForm).forEach(item => {
          if (item == 'isRepay' || item == 'type') {
            this.editForm[item] = 0
          } else {
            this.editForm[item] = undefined
          }
        })
        this.editDialogVisible = true
        this.dialogStatus = "create"
        this.$nextTick(() => {
          this.$refs['editForm'].clearValidate()
        })
      },

      // 弹出修改三方关联信息对话框
      handleEdit(row) {
        this.editForm = Object.assign({}, row);
        this.isSelectOptions()
        // this.editForm.selectedBankInfo = [row.bankCode, row.interBankNo]
        this.editForm.bankCode = this.editForm.bankCode
        this.editForm.bankName = this.editForm.interBankName
        if (this.bankInfo.length) {
          let bankArr = this.bankInfo.filter(item => {
            return row.bankCode == item.value
          })[0]
          // if (bankArr && !bankArr.children.length) {
          //   doGet('unionno.html?op=list', {bankName: bankArr.label}).then(response => {
          //     this.bankInfo.forEach(item => {
          //       if (item.value == bankArr.value) {
          //         item.children = response.rows.map(items => {
          //           return {
          //             value: items.interBankNo,
          //             label: items.bankName
          //           }
          //         })
          //       }
          //     })
          //   }).catch(() => {
          //     // this.bankInfo = []
          //   })
          // }
        }
        this.editIndex = this.list.indexOf(row);
        this.dialogStatus = "update"
        this.editDialogVisible = true
        this.$nextTick(() => {
          this.$refs['editForm'].clearValidate()
        })
      },

      // 提交三方关联信息
      doEdit() {
        this.$refs['editForm'].validate(valid => {
          if (valid) {
            this.editForm.isRepay = this.editForm.isRepay ? 1 : 0
            this.editForm.id = this.editForm.ID
            this.editForm.bankCode = this.editForm.bankCode
            this.editForm.bankName = this.editForm.bankName
            this.editForm.interBankNo = this.editForm.interBankNo
            /*this.editForm.selectedBankInfo = undefined*/
            doGet(`correlation.html?op=${this.dialogStatus == 'create' ? 'add' : 'chg'}`, this.editForm)
              .then(response => {
                this.getList()
                this.editDialogVisible = false
                this.$notify.success({
                  title: '成功',
                  message: this.dialogStatus == 'create' ? '添加三方关联成功' : '修改三方关联信息成功'
                })
              })
              .catch(response => {
                this.$notify.error({
                  title: '失败',
                  message: response.message
                })
              })
          }
        })
      },

      // 删除三方关联
      doDelete(row) {
        doGet("correlation.html?op=del", {...row, id: row.ID})
          .then(response => {
            this.$notify.success({
              title: '成功',
              message: '删除保理公司成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
            this.$refs[`popover-` + row.bankCode].doClose()
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.message
            })
          })
      },

      // 弹出余额对话框
      handleBalance(row) {
        this.acclist = []
        this.acclistDialogVisible = true
        this.getAccList(row.account)
      },

      // 弹出账户明细对话框
      handleBankserial(row) {
        this.account = row.account
        this.editChildForm.payRecv = 2
        this.editChildForm.queryDate = [parseTime(new Date(), '{y}-{m}-{d}'), parseTime(new Date(), '{y}-{m}-{d}')]
        this.acclistDialogChildVisible = true
        this.$nextTick(() => {
          this.$refs['editChildForm'].clearValidate()
        })
        this.getBankserialList(this.account)
      },

      // 获取明细列表
      getBankserialList(account) {
        this.bankserialListLoading = true
        let setData = {
          account: account,
          payRecv: this.editChildForm.payRecv == 2 ? undefined : this.editChildForm.payRecv,
          startTime: this.editChildForm.startTime,
          endTime: this.editChildForm.endTime,
          ...this.bankserialListQuery
        }
        doGet('bankserial.html?op=search', setData).then(response => {
          this.bankserialList = response.rows
          this.bankserialTotal = response.rows.length
          this.bankserialListLoading = false
        }).catch(() => {
          this.bankserialList = []
          this.bankserialTotal = 0
          this.bankserialListLoading = false
        })
      },

      // 查询明细列表
      doQuery() {
        this.$refs['editChildForm'].validate(valid => {
          if (valid) {
            this.getBankserialList(this.account)
          }
        })
      },

      // 获取保险公司列表
      getInsuranceList() {
        doGet('insurance.html?op=getCompanyListByType', {companyType: 0}).then(response => {
          this.insuranceList = response.rows
        }).catch(response => {
          this.insuranceList = []
          this.$notify.error({
            title: '失败',
            message: response.message
          })
        })
      },
        agenChange(id) {
            this.getAgens(id)
        },
        getAgens(id) {
            doGet('insurservice.html?op=acclist', { id }).then(response => {
                this.agens = response.rows
                this.agens.forEach((item) => {
                    this.editForm.account = item.account
                    this.editForm.accName = item.accName
                    this.editForm.bankCode = item.bankCode
                    this.editForm.bankName = item.interBankName
                    this.editForm.interBankNo = item.interBankNo
                })
            }).catch(() => {
                this.agens = []
            })
        },

      // 获取保代公司列表
      getAgentList() {
        doGet('insurance.html?op=getCompanyListByType', { companyType: 1 }).then(response => {
          this.agentList = response.rows
        }).catch(response => {
          this.agentList = []
          this.$notify.error({
            title: '失败',
            message: response.message
          })
        })
      },

      // 获取保理公司列表
      getFactoringList() {
        doGet('insurance.html?op=getCompanyListByType', {companyType: 2}).then(response => {
          this.factoringList = response.rows
        }).catch(response => {
          this.factoringList = []
          this.$notify.error({
            title: '失败',
            message: response.message
          })
        })
      },

      // 获取权益服务商列表
      getInsurserviceList() {
        doGet('insurance.html?op=getCompanyListByType', {companyType: 3}).then(response => {
          this.agentList = response.rows
        }).catch(response => {
          this.agentList = []
          this.$notify.error({
            title: '失败',
            message: response.message
          })
        })
      },

      // 获取服务账户列表
      getSurserviceList() {
        doGet('account.html?op=list').then(response => {
          this.surserviceList = response.rows.filter(item => {
            return item.accType == 0
          })
        }).catch(response => {
          this.surserviceList = []
          this.$notify.error({
            title: '失败',
            message: response.message
          })
        })
      },

      // 获取渠道编号列表
      getChannelNoList() {
        doGet('channel.html?op=channellist').then(response => {
          this.channelNoList = response.rows
        }).catch(response => {
          this.channelNoList = []
          this.$notify.error({
            title: '失败',
            message: response.message
          })
        })
      },

      // 获取银行代码信息
      getBankCodeInfo() {
        doGet('bank.html?op=list').then(response => {
          this.bankInfo = response.rows.map(item => {
            return {
              value: item.bankCode,
              label: item.bankName,
              children: []
            }
          })
          if (this.dialogStatus == "update") { // 修改信息执行
            let bankArr = this.bankInfo.filter(item => {
              return this.editForm.bankCode == item.value
            })[0]
            // if (bankArr && !bankArr.children.length) {
            //   doGet('unionno.html?op=list', {bankName: bankArr.label}).then(response => {
            //     this.bankInfo.forEach(item => {
            //       if (item.value == bankArr.value) {
            //         item.children = response.rows.map(items => {
            //           return {
            //             value: items.interBankNo,
            //             label: items.bankName
            //           }
            //         })
            //       }
            //     })
            //   }).catch(() => {
            //     // this.bankInfo = []
            //   })
            // }
          }
        }).catch(() => {
          this.bankInfo = []
        })
      },

      // 判断选择框的值
      isSelectOptions() {
        if (!this.insuranceList.length) {
          this.getInsuranceList()
        }
        if (!this.factoringList.length) {
          this.getFactoringList()
        }
        if (this.editForm.type == 0) {
          this.getAgentList()
        } else {
          this.getInsurserviceList()
        }
        if (!this.surserviceList.length) {
          this.getSurserviceList()
        }
        if (!this.channelNoList.length) {
          this.getChannelNoList()
        }
        if (!this.bankInfo.length) {
          this.getBankCodeInfo()
        }
      },

      // handleItemChange(val) {
      //   let bankArr = this.bankInfo.filter(item => {
      //     return item.value == val
      //   })[0]
      //   if (!bankArr.children.length) {
      //     doGet('unionno.html?op=list', {bankName:　bankArr.label}).then(response => {
      //       this.bankInfo.forEach(item => {
      //         if (item.value == val) {
      //           item.children = response.rows.map(items => {
      //             return {
      //               value: items.interBankNo,
      //               label: items.bankName
      //             }
      //           })
      //         }
      //       })
      //     }).catch(() => {
      //       // this.bankInfo = []
      //     })
      //   }
      // },

      typeChange(type) {
        this.editForm.agentID = undefined
        if (type == 0) {
          this.getAgentList()
        } else {
          this.getInsurserviceList()
        }
      },
        /**查询银行名称*/
        queryUnio() {
            this.UnionDialogVisible = true
            this.pageNum = this.pageNum
            this.pageSize = this.pageSize
            this.getUnionnos(this.al, '2')
        },
        getUnioLs() {
        if(this.al == null){
            alert('请选择共管账户银行代码')
          } else {
            this.UnionDialogVisible = true
            this.pageNum = this.pageNum
            this.pageSize = this.pageSize
            this.getUnionnos(this.al, '1')
          }
        },
        /** 选择分行*/
        choose(row) {
            this.editForm.interBankNo = row.interBankNo
            this.editForm1.interBankName = row.bankName
            this.editForm.bankName = row.bankName
            this.UnionDialogVisible = false
        },
    }
  }
</script>
